<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>选择培训人员</title>
		<!-- css代码 start -->
		<link href="../../../../css/mui.min.css" rel="stylesheet" />
		<link href="../../../../css/global.css" rel="stylesheet" />
		<link href="../../../../css/style.css" rel="stylesheet" />
		<link href="../../../../css/checkbox.css" rel="stylesheet" />
		<style>
			.mui-radio input[type=radio]{
				left: 0;
				top: 11px;
			}
			.mui-checkbox label, .mui-radio label{
				padding-left: 38px;
				font-size: 14px;
				color: #333333;
				padding-right: 0;
			}
		</style>
		<!-- css代码 end -->
	</head>
	<body>
		<!-- html代码 start -->
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">请选择培训人员</h1>
		</header>
		<div class="mui-content">

			<div class="page_cen shadow zp_cen">
				<div class="zp_sear autoHeight">
					<button class="btn" id="chaxun"></button>
					<div class="iptBox">
						<input type="text" id="tname" placeholder="请输入工程师名称" />
					</div>
				</div>
				<div class="jy_clum" id="peoples">
					<!-- <div class="mui-input-row mui-checkbox">
						<input name="checkbox1" value="张三" type="checkbox" />
						<label>张三</label>
					</div>
					<div class="mui-input-row mui-checkbox">
						<input name="checkbox1" value="李四" type="checkbox" />
						<label>李四</label>
					</div>
					<div class="mui-input-row mui-checkbox">
						<input name="checkbox1" value="李四" type="checkbox" />
						<label>李四</label>
					</div> -->
				</div>
			</div>
			<div class="btn_box">
				<span class="fl red one" id="submitBtn">确认</span>
			</div>
		</div>
		<!-- html代码 end -->

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../../js/mui.min.js"></script>
		<script src="../../../../js/utils/h.js"></script>
		<script src="../../../../js/constant.js"></script>
		<script src="../../../../js/common.js"></script>
		<script src="../../../../js/utils/base64.js"></script>
		<script src="../../../../js/utils/md5.js"></script>
		<script src="../../../../js/utils/sortMap.js"></script>
		<script src="../../../../js/utils/http.js"></script>
		<script src="../../../../js/app.js"></script>
		<!-- 基础js end -->

		<script type="text/javascript" charset="utf-8">
			(function($, doc) {
				$.init();

				var serviceNo, trainFseCode

				$.plusReady(function() {
					// 从上一个页面取值
					var self = plus.webview.currentWebview();
					var wo = self.opener();
					// 获取上一个页面传过来的参数并显示到页面
					serviceNo = self.serviceNo;
					trainFseCode = self.trainFseCode;

					var defaultChecked = function() {
						console.log(trainFseCode)
						if (trainFseCode) {
							var peopleIds = trainFseCode.split(',');
							for (var i = 0; i < peopleIds.length; i++) {
								document.querySelector(`input[name='checkbox1'][value='${peopleIds[i]}']`).checked = true;
							}
						}
					}

					var selectTrainPeople = function(serviceNo, fseName) {
						app.showWaiting()
						ajaxGet(BASE_URL + 'cc/ServiceDetails/selectTrainPeople', {
							serviceNo,
							fseName
						}, function(data) {
							app.closeWaiting()
							if (data.code === 200) {
								var peoples = data.data;
								var str = ``;
								for (var i = 0; i < peoples.length; i++) {
									str +=
										`
										<div class="mui-input-row mui-checkbox">
											<input name="checkbox1" value="${peoples[i].fseId}" type="checkbox" fseName="${peoples[i].fseName}"/>
											<label>${peoples[i].fseName}</label>
										</div>
									`;
								}
								h('#peoples').html(str);
								defaultChecked();
							} else {
								if (data.msg) {
									app.toast(data.msg);
								} else {
									app.toast();
								}
							}
						}, function(errorMsg) {
							app.closeWaiting();
							app.toast(errorMsg);
						});
					}

					var GetCheckboxName = function(checkboxName, attr) {
						var checkboxs = document.getElementsByName(checkboxName);
						var ck = new Array();
						var j = 0;
						for (var i = 0; i < checkboxs.length; i++) {
							var checkbox = checkboxs[i];
							if (checkbox.checked) {
								if (JS.IsNullOrEmpty(checkbox.getAttribute(attr))) return undefined;
								ck[j] = checkbox.getAttribute(attr);
								j++;
							}
						}
						return j == 0 ? undefined : ck.join();
					};

					selectTrainPeople(serviceNo);

					// 查询
					h('#chaxun').tap(function() {
						selectTrainPeople(serviceNo, h('#tname').val());
					});

					// 确认
					h('#submitBtn').tap(function() {
						var trainFse = GetCheckboxName('checkbox1', 'fseName');
						var trainFseCode = JS.GetCheckboxValue('checkbox1');
						if (JS.IsNullOrEmpty(trainFse)) {
							trainFse = ""
						}
						if (JS.IsNullOrEmpty(trainFseCode)) {
							trainFseCode = ""
						}
						wo.evalJS('updatetrainFse("' + trainFse + '", "' + trainFseCode + '")');
						$.back();
					});
				});

			}(mui, document));
		</script>
		<!-- js代码 end -->
	</body>
</html>
